package com.lcb.jmm.unsafe;

import com.lcb.jmm.volatiledome.UnsafeInstance;
import sun.misc.Unsafe;

/****
 * @Author:刘长柏
 * @Date: 2021-01-05 15:02
 * @Description:魔法类实现锁
 *****/
public class ObjectMonitorTest {

    static Object object = new Object();

    /*public void method1(){
        unsafe.monitorEnter(object);
    }

    public void method2(){
        unsafe.monitorExit(object);
    }*/
    public static void main(String[] args) {

        Unsafe unsafe = UnsafeInstance.reflectGetUnsafe();
        unsafe.monitorEnter(object);
        //业务逻辑
        unsafe.monitorExit(object);
    }

}
